package com.codeying.servlet.car;

import com.codeying.servlet.AbsServlet;
import com.codeying.entity.*;
import com.codeying.utils.*;
import org.json.JSONObject;
import com.codeying.utils.component.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 删除汽车
 */
@WebServlet("/car/delete")
public class DeleteCarServlet  extends AbsServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        req.setCharacterEncoding("utf-8");
        resp.setHeader("Content-type", "text/html;charset=UTF-8");
        resp.setContentType("application/json; charset=utf-8");
        resp.setCharacterEncoding("UTF-8");
        //获取被删除数据的id
        String id = req.getParameter("id");
        Car delTemp = carService.getById(id);
        //=========删除之前
    
        //=========删除之前
        //执行删除
        int res = carService.deleteById(id);
        if(res==1){
            resp.getWriter().print(ApiResult.success());//标记删除成功
        }else {
            resp.getWriter().print(ApiResult.fail("删除失败"));//删除失败
        }
    }
}

